package com.maksdu.LactiveMQ.factory;

import com.maksdu.LactiveMQ.broker.LactiveBroker;
import com.maksdu.LactiveMQ.core.AbstractExchange;
import com.maksdu.LactiveMQ.core.Exchange;
import com.maksdu.LactiveMQ.domain.Message;
import com.maksdu.LactiveMQ.domain.MessageHost;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class HostBrokerFactory extends AbstractExchange implements Exchange, BrokerAction {

    private ConcurrentMap<String, LactiveBroker> brokerMap = new ConcurrentHashMap<>();

    @Override
    public void registry(String topic, LactiveBroker newBroker) {
        LactiveBroker broker = getBroker(topic);
        if(broker == null) {
            brokerMap.put(topic, newBroker);
        }
    }

    @Override
    public LactiveBroker getBroker(String topic) {
        return brokerMap.getOrDefault(topic, null);
    }
}
